//
//  COCallBottomView.swift
//  CocoProject
//
//  Created by Vill on 2023/11/15.
//

import UIKit

// type 1:聊天 2:麦克风 3:礼物
typealias bottomBtnBlock = (_ type:Int,_ btn:UIButton?)->Void

class COCallBottomView: UIView {

    var callBolck:bottomBtnBlock?
    
    lazy var chatToolView: UIView = {
        let chatTool = UIView()
        chatTool.backgroundColor =  UIColor.colorWithHex("#3F376C", 0.58)
        chatTool.layer.cornerRadius = PTW(25)
        chatTool.layer.masksToBounds = true
        chatTool.addTap { [weak self] ges in
            guard let `self` = self else { return }
            if self.callBolck != nil{
                self.callBolck!(1,nil)
            }
        }
        return chatTool
    }()
    
    lazy var hiLbl: UILabel = {
        let name = UILabel()
        name.textColor = UIColor.colorWithHex("#FFFFFF",0.6)
        name.font = UIFont.pingfangFont(ofSize: PTW(15), weight: .medium)
        name.text = "Say hi~"
        return name
    }()
    

    // 麦克风
    lazy var micBtn: UIButton = {
        let i = UIButton()
        i.setImage(KImaged("coco_video_micOff"), for: .selected)
        i.setImage(KImaged("coco_video_micOn"), for: .normal)
        i.addTarget(self, action: #selector(micAction), for: .touchUpInside)
        return i
    }()
    
    //礼物
    lazy var giftBtn: UIButton = {
        let i = UIButton()
        i.setImage(KImaged("coco_call_gift"), for: .normal)
        i.addTarget(self, action: #selector(giftAction), for: .touchUpInside)
        return i
    }()

    @objc func micAction(sender:UIButton){
        if self.callBolck != nil{
            self.callBolck!(2,sender)
        }
    }
    
    @objc func giftAction(sender:UIButton){
        if self.callBolck != nil{
            self.callBolck!(3,nil)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func addUI(){
        addSubview(chatToolView)
        chatToolView.addSubview(hiLbl)
        addSubview(micBtn)
        addSubview(giftBtn)
        chatToolView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(PTW(20))
            make.trailing.equalToSuperview().offset(-PTW(130))
            make.centerY.equalToSuperview()
            make.height.equalTo(PTW(50))
        }
        
        hiLbl.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.leading.equalTo(chatToolView).offset(PTW(20))
        }
        
        micBtn.snp.makeConstraints { make in
            make.size.equalTo(PTW(50))
            make.centerY.equalToSuperview()
            make.leading.equalTo(chatToolView.snp.trailing).offset(PTW(5))
        }
        giftBtn.snp.makeConstraints { make in
            make.size.equalTo(PTW(50))
            make.centerY.equalToSuperview()
            make.leading.equalTo(micBtn.snp.trailing).offset(PTW(5))
        }
    }
}
